package com.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.constant.MessageConstant;
import com.shop.entity.QueryPageBean;
import com.shop.entity.Result;
import com.shop.pojo.Orders;
import com.shop.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
@Api(tags = "订单管理")
public class OrdersController {
    @Reference
    private OrdersService orderService;

    @PreAuthorize("hasAuthority('QUERY_ORDERS')")
    @PostMapping("/pageQuery")
    @ApiOperation("订单分页接口")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        Page<Orders> page=orderService.pageQuery(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),queryPageBean.getQueryString());
        return new Result(true,MessageConstant.QUERY_ORDERS_SUCCESS,page);
    }

    @PreAuthorize("hasAuthority('EDIT_ORDERS')")
    @PutMapping("/edit")
    @ApiOperation("订单发货接口")
    public Result edit(@RequestBody Orders orders){
        try {
            orderService.edit(orders);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_ORDERS_FAIL);
        }
        return new Result(true,MessageConstant.EDIT_ORDERS_SUCCESS);
    }


}
